<template>
	<view class="detail-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="通知公告详情"></uni-navbar></view>

		<view class="detail-info" v-show="announcements.id">
			<view class="info-title">
				<view class="title-top">{{ announcements.title }}</view>
				<view class="title-btm">
					<text class="btm-name">{{ announcements.createName }}</text>
					<text class="btm-time">{{ announcements.createTime }}</text>
					<text class="btm-num">{{ announcements.readNum > 0 ? announcements.readNum : 0 }}人已阅</text>
				</view>
			</view>
			<view class="info-detail">
				<view class="overflow"><uni-parse :content="announcements.content"></uni-parse></view>
			</view>
		</view>

		<!-- <view class="uploader-add" @click="onTts">
			<image v-if="!play" src="/static/img/icon_76.png" mode="widthFix"></image>
			<image src="/static/img/icon_77.gif" v-else mode="widthFix"></image>
		</view> -->

		<view class="file-list" v-if="announcements.outLink">
			<view>外部链接:</view>
			<view class="link" @click="navTo(announcements.outLink)">{{ announcements.outLink }}</view>
		</view>

		<view class="file-list" v-if="fileList.length > 0">
			<view>附件:</view>
			<view class="file-item" v-for="(item, index) in fileList" :key="index" @click="$showLine(item)">
				<view class="file-name clamp">{{ item.name }}</view>
				<view class="right-type">预览</view>
			</view>
		</view>

		<view class="fiexd-btm" v-if="$sysBtns('tzgg_bm') && announcements.attenderCount > 0">
			<block v-if="signStatus != '2' && hasSign == '1'"><u-button class="form-btn" type="error" @click="cxbm()">撤销报名</u-button></block>
			<block v-else-if="signStatus == '0'"><u-button class="form-btn" type="error" @click="bm()">报名参加</u-button></block>
			<block v-if="signStatus == '1' && hasSign != '1'"><u-button class="form-btn">名额已满！期待下次参加</u-button></block>
			<block v-if="signStatus == '2'"><u-button class="form-btn">报名已截止！</u-button></block>
		</view>
	</view>
</template>

<script>
import uniParse from '@/components/uni-parse/parse.vue';
import { mapState } from 'vuex';
export default {
	components: {
		uniParse
	},
	data() {
		return {
			id: '',
			fileList: [],
			announcements: '',
			hasSign: '',
			signStatus: '',
			play: false
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.id = option.id;
		this.loadData();
	},
	onHide() {
		this.$ttsOff();
	},
	onUnload() {
		this.$ttsOff();
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.sysUser) {
				this.userId = this.userInfo.sysUser.id;
				this.clientCode = this.userInfo.sysUser.clientCode;
			} else {
				this.$logout();
			}
		},
		loadData() {
			let data = {
				announcementsInfo: {
					mainId: this.id,
					userId: this.userId
				}
			};
			this.$request('/announcements/query/' + this.id + '/' + this.clientCode + '/' + this.userId).then((res) => {
				this.announcements = res.data.announcements;
				this.hasSign = res.data.hasSign || '0';
				this.signStatus = res.data.signStatus || '0';
				this.fileList = res.data.fileList;
			});
		},
		bm() {
			let data = {
				attender: {
					mainId: this.id,
					userId: this.userId
				}
			};
			this.$request('/announcementsattender/add', data).then((res) => {
				this.$msg(res.msg);
				this.loadData();
			});
		},
		cxbm() {
			let data = {
				attender: {
					mainId: this.id,
					userId: this.userId
				}
			};
			this.$request('/announcementsattender/cancel', data).then((res) => {
				this.$msg(res.msg);
				this.loadData();
			});
		},
		navTo(url) {
			uni.setClipboardData({
				data: url,
				success: () => {
					console.log('success');
				}
			});
		},
		onTts() {
			let text = this.announcements.title;
			text += ',' + this.announcements.createName;
			text += ',' + this.$parseTime(this.announcements.createTime, '{y}-{m}-{d}');
			text += ',' + this.$htmlRegx(this.announcements.content);
			this.$tts(text, this, 500);
		}
	}
};
</script>

<style lang="scss">
.detail-view {
	background-color: #fff;
}

.fiexd-btm {
	position: static;
	border-top: 10rpx solid #f5f7fa;
	padding: 30rpx;
}
</style>
